﻿///*
// * RGBPalette (original name Palette)
// *
// * Copyright (c) 2000, 2001, 2002, 2003 Marco Schmidt.
// * All rights reserved.
// * port to C#.NET by asida@centrum.cz
// */
//using System;
//using System.Collections.Generic;
//using System.Text;



//namespace Petra.Gis.Geometry.Image.Tiff
//{


///**
// * This class represents a palette, a list of RGB colors.
// * An RGB color here has three int values for its red, green and blue
// * intensity.
// * Each intensity value must be larger than or equal to zero and
// * smaller than or equal to the maximum intensity value that can be
// * given to the constructor {@link #RGBPalette(int, int)}.
// * This maximum value is typically 255.
// * Note that the number of entries in a palette is restricted only
// * by the element index type <code>int</code> so that palettes with
// * more than 256 entries are no problem.
// * When accessing (reading or writing) samples of this palette, use
// * the constants {@link #Red}, {@link #Green} and {@link #Blue} of
// * this class to define a color channel.
// * @author Marco Schmidt
// * @see net.sourceforge.jiu.data.PalettedImage
// */
//public class RGBPalette //implements RGBIndex
//{

//  private static int Red = 0;
//  private static int Green = 1;
//  private static int Blue = 2;

//  private int[][] data;
//  private int numEntries;
//  private int maxValue;

//  /**
//   * Create a palette with the given number of entries and a maximum value
//   * for each sample.
//   * @param numEntries the number of entries to be accessible in this palette
//   * @param maxValue the maximum value to be allowed for each sample
//   */
//  public RGBPalette(int numEntries, int maxValue)
//  {
//    if (numEntries < 1)
//    {
//      throw new ArgumentException("Error -- numEntries must be larger than 0.");
//    }
//    this.numEntries = numEntries;
//    this.maxValue = maxValue;
//    data = new int[3][];
//    for (int i = 0; i < 3; i++)
//    {
//      data[i] = new int[numEntries];
//    }
//  }




//  /**
//   * Create a palette with the given number of entries and a maximum value
//   * of <code>255</code>.
//   * @param numEntries the number of entries to be accessible in this palette
//   */
//  public RGBPalette(int numEntries)
//    : this(numEntries, 255)
//  {}




//  /**
//   * Creates a copy of this palette, allocating a new RGBPalette object
//   * and copying each RGB triplet to the new palette.
//   * Then returns the new palette.
//   * Thus, a &quot;deep&quot; copy of this RGBPalette object is created,
//   * not a &quot;shallow&quot; one.
//   *
//   * @return newly-created palette
//   */
//  public Object clone()
//  {
//    RGBPalette result = new RGBPalette(getNumEntries(), getMaxValue());
//    for (int i = 0; i < getNumEntries(); i++)
//    {
//      result.putSample(RGBIndex.Red, i, getSample(RGBIndex.Red, i));
//      result.putSample(RGBIndex.Green, i, getSample(RGBIndex.Green, i));
//      result.putSample(RGBIndex.Blue, i, getSample(RGBIndex.Blue, i));
//    }
//    return result;
//  }





//  /**
//   * Returns the amount of memory in bytes allocated for this palette.
//   *
//   */
//  public long getAllocatedMemory()
//  {
//    long result = 0;
//    if (data != null)
//    {
//      for (int i = 0; i < data.Length; i++)
//      {
//        if (data[i] != null)
//        {
//          result += data[i].Length;
//        }
//      }
//    }
//    return result;
//  }





//  /**
//   * Returns the maximum value allowed for a sample.
//   * @return the maximum sample value
//   */
//  public int getMaxValue()
//  {
//    return maxValue;
//  }





//  /**
//   * Returns the number of entries in this palette.
//   * @return the number of entries in this palette
//   */
//  public int getNumEntries()
//  {
//    return numEntries;
//  }




//  /**
//   * Returns one of the samples of this palette.
//   * @param entryIndex the index of the color to be addressed, must be from
//   *  <code>0</code> to <code>getNumEntries() - 1</code>
//   * @param channelIndex one of the three channels; must be {@link #Red},
//   *  {@link #Green} or {@link #Blue}
//   * @return the requested sample
//   */
//  public int getSample(RGBIndex channelIndex, int entryIndex)
//  {
//    try
//    {
//      return data[(int)channelIndex][entryIndex];
//    }
//    catch (IndexOutOfRangeException aioobe)
//    {
//      throw new ArgumentException("Entry must be from 0 to " + (numEntries - 1) +
//        ", channel from 0 to 2.");
//    }
//  }




//  /**
//   * Returns all samples of one channel as an int array.
//   * @param channelIndex index of the channel, one of the {@link RGBIndex} constants
//   * @return array with samples
//   */
//  public int[] getSamples(RGBIndex channelIndex)
//  {
//    if (channelIndex < 0 || (int)channelIndex > 2)
//    {
//      throw new ArgumentException("Invalid channel index, must be from 0 to 2.");
//    }
//    int[] result = new int[data[(int)channelIndex].Length];
//    Array.Copy(data[(int)channelIndex], 0, result, 0, result.Length);

//    return result;
//  }




//  /**
//   * Checks if all entries of this palette are either black or white.
//   * An entry is black if all three intensitites (red, green and blue) are
//   * <code>0</code>, it is white if they are all equal to 
//   * {@link #getMaxValue()}.
//   * No particular order of entries (e.g. first color black, second white)
//   * is demanded and no specific number of entries (e.g. 2).
//   * This means that a palette is black and white if it contains ten entries
//   * that are all black.
//   *
//   * @return if the palette contains only the colors black and white
//   */
//  public bool isBlackAndWhite()
//  {
//    int i = 0;
//    while (i < numEntries)
//    {
//      if (data[Red][i] != data[Green][i] ||
//          data[Green][i] != data[Blue][i] ||
//          (data[Blue][i] != 0 && data[Blue][i] != maxValue))
//      {
//        return false;
//      }
//      i++;
//    }
//    return true;
//  }




//  /**
//   * Checks if this palette is gray, i.e., checks if all entries are
//   * gray. This is the case if for all entries red, green and blue
//   * have the same intensity.
//   * @return if the palette contains only shades of gray
//   */
//  public bool isGray()
//  {
//    int i = 0;
//    while (i < numEntries)
//    {
//      if (data[Red][i] != data[Green][i] ||
//          data[Green][i] != data[Blue][i])
//      {
//        return false;
//      }
//      i++;
//    }
//    return true;
//  }




//  public void put(int entryIndex, int red, int green, int blue)
//  {
//    putSample(RGBIndex.Red, entryIndex, red);
//    putSample(RGBIndex.Green, entryIndex, green);
//    putSample(RGBIndex.Blue, entryIndex, blue);
//  }





//  /**
//   * Sets one sample of one color entry in the palette to a new value.
//   * @param channelIndex 
//   */
//  public void putSample(RGBIndex channelIndex, int entryIndex, int newValue)
//  {
//    if (newValue < 0 || newValue > maxValue)
//    {
//      throw new ArgumentException("Value must be from 0 to " +
//        maxValue + "; argument is " + newValue + ".");
//    }
//    try
//    {
//      data[(int)channelIndex][entryIndex] = newValue;
//    }
//    catch (IndexOutOfRangeException ioobe)
//    {
//      throw new ArgumentException("Entry must be from 0 to " + (numEntries - 1) +
//        ", channel from 0 to 2.");
//    }
//  }
//}

//}
